﻿using System;
using System.Collections.Generic;
using Framework.Helper;
using MongoDB.Driver;
using SignalPositionProcesser.Entities;

namespace SignalPositionProcesser.DataAccess
{
    public class ChannelDataDA
    {
        private readonly IMongoCollection<Channel> channelCollection;
        public ChannelDataDA()
        {
            var client = new MongoClient(ConfigurationHelper.GetConfiguration("ConnectionString"));
            var database = client.GetDatabase(ConfigurationHelper.GetConfiguration("DBInstance"));
            channelCollection = database.GetCollection<Channel>(ConfigurationHelper.GetConfiguration("ChannelCollection"));
        }

        public IMongoCollection<Channel> Collection
        {
            get { return channelCollection; }
        }

        public void SaveMany(List<Channel> channelList)
        {
            try
            {
                channelCollection.InsertMany(channelList);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
    }
}
